package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ITZhgdDeviceToolsInfoService;
import com.ruoyi.system.service.ITZhgdDeviceToolsStorageHistoryService;
import com.ruoyi.system.service.ITZhgdDeviceToolsStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysDataSyncMapper;
import com.ruoyi.system.domain.SysDataSync;
import com.ruoyi.system.service.ISysDataSyncService;
import com.ruoyi.common.core.text.Convert;

/**
 * 信息同步Service业务层处理
 * 
 * @author wuyafeng
 * @date 2025-01-19
 */
@EnableAsync
@Service
public class SysDataSyncServiceImpl implements ISysDataSyncService 
{
    @Autowired
    private SysDataSyncMapper sysDataSyncMapper;
    @Autowired
    ITZhgdDeviceToolsInfoService toolsInfoService;
    @Autowired
    ITZhgdDeviceToolsStorageHistoryService toolsStorageHistoryService;
    @Autowired
    ITZhgdDeviceToolsStorageService toolsStorageService;

    /**
     * 查询信息同步
     * 
     * @param id 信息同步主键
     * @return 信息同步
     */
    @Override
    public SysDataSync selectSysDataSyncById(Integer id)
    {
        return sysDataSyncMapper.selectSysDataSyncById(id);
    }

    /**
     * 查询信息同步列表
     * 
     * @param sysDataSync 信息同步
     * @return 信息同步
     */
    @Override
    public List<SysDataSync> selectSysDataSyncList(SysDataSync sysDataSync)
    {
        return sysDataSyncMapper.selectSysDataSyncList(sysDataSync);
    }

    /**
     * 新增信息同步
     * 
     * @param sysDataSync 信息同步
     * @return 结果
     */
    @Override
    public int insertSysDataSync(SysDataSync sysDataSync)
    {
        sysDataSync.setCreateTime(DateUtils.getNowDate());
        return sysDataSyncMapper.insertSysDataSync(sysDataSync);
    }

    /**
     * 修改信息同步
     * 
     * @param sysDataSync 信息同步
     * @return 结果
     */
    @Override
    public int updateSysDataSync(SysDataSync sysDataSync)
    {
        sysDataSync.setUpdateTime(DateUtils.getNowDate());
        return sysDataSyncMapper.updateSysDataSync(sysDataSync);
    }

    /**
     * 信息同步上传数据
     *
     * @param sysDataSync 信息同步
     * @return 结果
     */
    @Override
    public boolean uploadDataSync(SysDataSync sysDataSync)
    {
        //上传
        toolsInfoService.uploadToolsInfo(sysDataSync.getProjectUrl(),sysDataSync.getProjectId());
        toolsStorageHistoryService.uploadStorageHistory(sysDataSync.getProjectUrl(),sysDataSync.getProjectId());
        toolsStorageService.uploadToolsStorage(sysDataSync.getProjectUrl(),sysDataSync.getProjectId());
        sysDataSync.setUpdateTime(DateUtils.getNowDate());
        return true;
    }

    /**
     * 批量删除信息同步
     * 
     * @param ids 需要删除的信息同步主键
     * @return 结果
     */
    @Override
    public int deleteSysDataSyncByIds(String ids)
    {
        return sysDataSyncMapper.deleteSysDataSyncByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除信息同步信息
     * 
     * @param id 信息同步主键
     * @return 结果
     */
    @Override
    public int deleteSysDataSyncById(Integer id)
    {
        return sysDataSyncMapper.deleteSysDataSyncById(id);
    }
}
